<?php
if(defined("IZ_ACCNAME")) {
function appendcategoryNode($dom, $category, $parentnode) {
  $categoryNode = $dom->createElement('category');
  $categoryNode->setAttribute('name',clean($category->name));

  $categoryNode->appendChild($dom->createElement('id',$category->id));
  $categoryNode->appendChild($dom->createElement('name',clean($category->name)));
  $categoryNode->appendChild($dom->createElement('owner',clean($category->owner)));
  $categoryNode->appendChild($dom->createElement('type',$category->type));
  $categoryNode->appendChild($dom->createElement('ispublic',$category->public));
  $categoryNode->appendChild($dom->createElement('backgroundcolor',parsecolor($category->color)));

  $parentnode->appendChild($categoryNode);
}
function appendcommentNode($dom, $comment, $parentnode) {
  $commentNode = $dom->createElement('comment');
  
  $commentNode->appendChild($dom->createElement('id',$comment->id));
  $commentNode->appendChild($dom->createElement('postid',$comment->postid));
  $commentNode->appendChild($dom->createElement('author',clean($comment->author)));
  $commentNode->appendChild($dom->createElement('posted',date("Y-m-d\TH:i:s",$comment->posted)));
  $commentNode->appendChild($dom->createElement('text',clean($comment->text)));

  $parentnode->appendChild($commentNode);
}
function appendeventNode($dom, $event, $parentnode) {
  $eventNode = $dom->createElement('event');
  $eventNode->setAttribute('title',clean($event->title));
  
  $eventNode->appendChild($dom->createElement('id',$event->id));
  $eventNode->appendChild($dom->createElement('category',$event->category));
  $eventNode->appendChild($dom->createElement('title',clean($event->title)));
  $eventNode->appendChild($dom->createElement('description',clean($event->description)));
  $eventNode->appendChild($dom->createElement('venue',clean($event->venue)));
  $eventNode->appendChild($dom->createElement('instanceof',$event->instanceof));
  $eventNode->appendChild($dom->createElement('author',clean($event->author)));
  $eventNode->appendChild($dom->createElement('cust1',clean($event->cust1)));
  $eventNode->appendChild($dom->createElement('cust2',clean($event->cust2)));
  $eventNode->appendChild($dom->createElement('cust3',clean($event->cust3)));
  $eventNode->appendChild($dom->createElement('attendees',clean($event->attendees)));
  $eventNode->appendChild($dom->createElement('comments',$event->comments));
  $eventNode->appendChild($dom->createElement('icon',$event->icon));
  $eventNode->appendChild($dom->createElement('status',$event->status));
  $eventNode->appendChild($dom->createElement('linkgoogle',$event->linkgoogle));
  $eventNode->appendChild($dom->createElement('allday',$event->allday));
  $eventNode->appendChild($dom->createElement('startdate',date("Y-m-d\TH:i:s",$event->eventstart)));
  $eventNode->appendChild($dom->createElement('enddate',date("Y-m-d\TH:i:s",$event->eventend)));
  $parentnode->appendChild($eventNode);
}
function appendtaskNode($dom, $task, $parentnode) {
  $taskNode = $dom->createElement('task');
  $taskNode->setAttribute('title',clean($task->title));
  
  $taskNode->appendChild($dom->createElement('id',$task->id));
  $taskNode->appendChild($dom->createElement('category',$task->category));
  $taskNode->appendChild($dom->createElement('title',clean($task->title)));
  $taskNode->appendChild($dom->createElement('description',clean($task->description)));
  $taskNode->appendChild($dom->createElement('author',clean($task->author)));
  $taskNode->appendChild($dom->createElement('created',date("Y-m-d\TH:i:s",$task->created)));
  $taskNode->appendChild($dom->createElement('due',date("Y-m-d\TH:i:s",$task->due)));
  $taskNode->appendChild($dom->createElement('cust1',clean($task->cust1)));
  $taskNode->appendChild($dom->createElement('cust2',clean($task->cust2)));
  $taskNode->appendChild($dom->createElement('cust3',clean($task->cust3)));
  $taskNode->appendChild($dom->createElement('comments',$task->comments));
  $taskNode->appendChild($dom->createElement('status',$task->status));
  $taskNode->appendChild($dom->createElement('complete',$task->complete));
  $taskNode->appendChild($dom->createElement('icon',$task->icon));

  $parentnode->appendChild($taskNode);
}
function appenduserNode($dom, $user, $parentnode) {
  $userNode = $dom->createElement('user');
  
  $userNode->appendChild($dom->createElement('id',$user->id));
  $userNode->appendChild($dom->createElement('name',clean($user->name)));
  $userNode->appendChild($dom->createElement('usergroup',$user->usergroup));
  $userNode->appendChild($dom->createElement('password',$user->password));
  $userNode->appendChild($dom->createElement('language',$user->language));
  $userNode->appendChild($dom->createElement('daysize',$user->daysize));
  $userNode->appendChild($dom->createElement('firstdayofweek',$user->firstdayofweek));
  $userNode->appendChild($dom->createElement('theme',$user->theme));
  $userNode->appendChild($dom->createElement('dateformat',$user->dateformat));
  $userNode->appendChild($dom->createElement('defaultcategoryevents',$user->dateformat));
  $userNode->appendChild($dom->createElement('defaultcategorytasks',$user->defaultcategorytasks));
  $userNode->appendChild($dom->createElement('fontsize',$user->fontsize));
  $userNode->appendChild($dom->createElement('collapsestatus',$user->collapsestatus));
  $userNode->appendChild($dom->createElement('color',parsecolor($user->color)));
  $userNode->appendChild($dom->createElement('defaultstatus',$user->defaultstatus));
  $userNode->appendChild($dom->createElement('showall',$user->showall));
  $userNode->appendChild($dom->createElement('pageafter',$user->pageafter));
  $userNode->appendChild($dom->createElement('viewdetails',$user->viewdetails));
  $userNode->appendChild($dom->createElement('includecomplete',$user->includecomplete));

  $parentnode->appendChild($userNode);
}
function appendgroupNode($dom, $group, $parentnode) {
  $groupNode = $dom->createElement('group');
  
  $groupNode->appendChild($dom->createElement('id',$group->id));
  $groupNode->appendChild($dom->createElement('name',clean($group->name)));
  $groupNode->appendChild($dom->createElement('canview',$group->view));
  $groupNode->appendChild($dom->createElement('canedit',$group->edit));
  $groupNode->appendChild($dom->createElement('candelete',$group->delete));
  $groupNode->appendChild($dom->createElement('canadministrate',$group->cpanel));
  $groupNode->appendChild($dom->createElement('cancustomise',$group->customise));
  $groupNode->appendChild($dom->createElement('cancomment',$group->comment));

  $parentnode->appendChild($groupNode);
}
function appendsettingNode($dom, $setting, $parentnode) {
  $settingNode = $dom->createElement('setting',$setting->setval);
  $settingNode->setAttribute('name',$setting->name);
  $parentnode->appendChild($settingNode);
}
function exportXml() {
  izsql();
  $dom = new DOMDocument('1.0', 'UTF-8');
  $dom->preserveWhiteSpace = false;
  $dom->formatOutput = true;
  $root = $dom->createElement('calendar');
  $dom->appendChild($root);
  
  $metaData = $dom->createElement('meta');
  $root->appendChild($metaData);
  $metaData->appendChild($dom->createElement('generator','iZeit'));
  $metaData->appendChild($dom->createElement('version',IZ_CALVERSION));
  $metaData->appendChild($dom->createElement('locale',$_SESSION['IZ_LANG']));
  $metaData->appendChild($dom->createElement('exportdate',date('Y-m-d')));
  
  $events = $dom->createElement('events');
  $root->appendChild($events);
  $tasks = $dom->createElement('tasks');
  $root->appendChild($tasks);
  $comments = $dom->createElement('comments');
  $root->appendChild($comments);
  $settings = $dom->createElement('settings');
  $root->appendChild($settings);
  $users = $dom->createElement('users');
  $root->appendChild($users);
  $groups = $dom->createElement('groups');
  $root->appendChild($groups);
  $categories = $dom->createElement('categories');
  $root->appendChild($categories);
  
  $queries = array('Ca' => 'SELECT * FROM categories',
                   'Co' => 'SELECT * FROM comments',
                   'E' => 'SELECT * FROM events',
                   'G' => 'SELECT * FROM groups',
                   'T' => 'SELECT * FROM tasks',
                   'S' => 'SELECT * FROM settings',
                   'U' => 'SELECT * FROM users');
  if(IZ_CALMODE == 'mysql') {
    if($_SESSION['MYSQLi']) {
      global $dblink;
      foreach($queries as $prefix => $q) {
        $res = $dblink->query($q);
        switch($prefix) {
          case 'E':
            while($event = $res->fetch_object()) {
              appendeventNode($dom, $event, $events);
            }
            break;
          case 'T':
            while($task = $res->fetch_object()) {
              appendtaskNode($dom, $task, $tasks);
            }
            break;
          case 'Co':
            while($comment = $res->fetch_object()) {
              appendcommentNode($dom, $comment, $comments);
            }
            break;
          case 'S':
            while($setting = $res->fetch_object()) {
              appendsettingNode($dom, $setting, $settings);
            }
            break;
          case 'U':
            while($user = $res->fetch_object()) {
              appenduserNode($dom, $user, $users);
            }
            break;
          case 'G':
            while($group = $res->fetch_object()) {
              appendgroupNode($dom, $group, $groups);
            }
            break;
          case 'Ca':
            while($category = $res->fetch_object()) {
              appendcategoryNode($dom, $category, $categories);
            }
            break;
        }
        $res->close();
      }
    } else {
      foreach($queries as $prefix => $q) {
        $res = mysql_query($q);
        switch($prefix) {
          case 'E':
            while($event = mysql_fetch_object($res)) {
              appendeventNode($dom, $event, $events);
            }
            break;
          case 'T':
            while($task = mysql_fetch_object($res)) {
              appendtaskNode($dom, $task, $tasks);
            }
            break;
          case 'Co':
            while($comment = mysql_fetch_object($res)) {
              appendcommentNode($dom, $comment, $comments);
            }
            break;
          case 'S':
            while($setting = mysql_fetch_row($res)) {
              appendsettingNode($dom, $setting, $settings);
            }
            break;
          case 'U':
            while($user = mysql_fetch_object($res)) {
              appenduserNode($dom, $user, $users);
            }
            break;
          case 'G':
            while($group = mysql_fetch_object($res)) {
              appendgroupNode($dom, $group, $groups);
            }
            break;
          case 'Ca':
            while($category = mysql_fetch_object($res)) {
              appendcategoryNode($dom, $category, $categories);
            }
            break;
        }
      }
    }
  } elseif(IZ_CALMODE == 'postgre') {
    $queries = array('Ca' => 'SELECT * FROM "categories"',
                     'Co' => 'SELECT * FROM "comments"',
                     'E' => 'SELECT * FROM "events"',
                     'G' => 'SELECT * FROM "groups"',
                     'T' => 'SELECT * FROM "tasks"',
                     'S' => 'SELECT * FROM "settings"',
                     'U' => 'SELECT * FROM "users"');
    foreach($queries as $prefix => $q) {
      $res = pg_query($q);
      switch($prefix) {
        case 'E':
          while($event = pg_fetch_object($res)) {
            appendeventNode($dom, $event, $events);
          }
          break;
        case 'T':
          while($task = pg_fetch_object($res)) {
            appendtaskNode($dom, $task, $tasks);
          }
          break;
        case 'Co':
          while($comment = pg_fetch_object($res)) {
            appendcommentNode($dom, $comment, $comments);
          }
          break;
        case 'S':
          while($setting = pg_fetch_object($res)) {
            appendsettingNode($dom, $setting, $settings);
          }
          break;
        case 'U':
          while($user = pg_fetch_object($res)) {
            appenduserNode($dom, $user, $users);
          }
          break;
        case 'G':
          while($group = pg_fetch_object($res)) {
            appendgroupNode($dom, $group, $groups);
          }
          break;
        case 'Ca':
          while($category = pg_fetch_object($res)) {
            appendcategoryNode($dom, $category, $categories);
          }
          break;
      }
    }
  } elseif(IZ_CALMODE == 'msq') {
    foreach($queries as $prefix => $q) {
      $res = mssql_query($q);
      switch($prefix) {
        case 'E':
          while($event = mssql_fetch_object($res)) {
            appendeventNode($dom, $event, $events);
          }
          break;
        case 'T':
          while($task = mssql_fetch_object($res)) {
            appendtaskNode($dom, $task, $tasks);
          }
          break;
        case 'Co':
          while($comment = mssql_fetch_object($res)) {
            appendcommentNode($dom, $comment, $comments);
          }
          break;
        case 'S':
          while($setting = mssql_fetch_object($res)) {
            appendsettingNode($dom, $setting, $settings);
          }
          break;
        case 'U':
          while($user = mssql_fetch_object($res)) {
            appenduserNode($dom, $user, $users);
          }
          break;
        case 'G':
          while($group = mssql_fetch_object($res)) {
            appendgroupNode($dom, $group, $groups);
          }
          break;
        case 'Ca':
          while($category = mssql_fetch_object($res)) {
            appendcategoryNode($dom, $category, $categories);
          }
          break;
      }
    }
  }
  return utf8_encode($dom->saveXML());
}
function importXml($filename, $preview) {
  global $lcats;
  global $lusers;
  global $oldpasswords;
  if(file_exists($filename)) {
    $dom = new DomDocument();
    $dom->load($filename);
    $datenode = $dom->getElementsByTagname('exportdate');
    if(sizeof($datenode) > 0) {
      $_SESSION['backupmeta']['date'] = $datenode->item(0)->nodeValue;
    }
    $versionnode = $dom->getElementsByTagname('version');
    if(sizeof($versionnode) > 0) {
      $_SESSION['backupmeta']['izver'] = $versionnode->item(0)->nodeValue;
    }
    $generatornode = $dom->getElementsByTagname('generator');
    if(sizeof($generatornode) > 0) {
      $_SESSION['backupmeta']['generator'] = $generatornode->item(0)->nodeValue;
    }
    
    $eventnodes = $dom->getElementsByTagname('event');
    foreach($eventnodes as $eventnode) {
      $id = '';
      $category = '';      
      $title = '';
      $description = '';
      $venue = '';
      $instanceof = '';
      $author = '';
      $cust1 = '';
      $cust2 = '';
      $cust3 = '';
      $attendees = '';
      $comments = '';
      $icon = '';
      $status = '';
      $linkgoogle = '';
      $allday = '';
      $eventstart = '';
      $eventend = '';
      
      $subnodes = $eventnode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'category':
            $category = $subnode->nodeValue;
            break;
          case 'title':
            $title = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'description':
            $description = xmlUnescapeDbEscapeHTML($subnode->nodeValue);
            break;
          case 'venue':
            $venue = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'instanceOf':
            $instanceof = $subnode->nodeValue;
            break;
          case 'author':
            $author = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'cust1':
            $cust1 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'cust2':
            $cust2 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'cust3':
            $cust3 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'attendees':
            $attendees = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'comments':
            $comments = $subnode->nodeValue;
            break;
          case 'icon':
            $icon = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'status':
            $status = $subnode->nodeValue;
            break;
          case 'linkgoogle':
            $linkgoogle = $subnode->nodeValue;
            break;
          case 'allday':
            $allday = $subnode->nodeValue;
            break;
          case 'startdate':
            $eventstart = parseDotNetDate($subnode->nodeValue);
            break;
          case 'enddate':
            $eventend = parseDotNetDate($subnode->nodeValue);
            break;
        }
      }
      $_SESSION['fevents'][] = "$id','$category','$eventstart','$eventend','$title','$description','$venue','$linkgoogle','$allday','$instanceof','$status','$author','$cust1','$cust2','$cust3','$attendees','$comments','$icon";
    }
    
    $tasknodes = $dom->getElementsByTagname('task');
    foreach($tasknodes as $tasknode) {
      $id = '';
      $category = '';      
      $title = '';
      $description = '';
      $author = '';
      $createdDate = ''; 
      $due = '';
      $cust1 = '';
      $cust2 = '';
      $cust3 = '';
      $comments = '';
      $status = '';
      $complete = '';
      $icon = '-1';
      
      $subnodes = $tasknode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'category':
            $category = $subnode->nodeValue;
            break;
          case 'title':
            $title = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'description':
            $description = xmlUnescapeDbEscapeHTML($subnode->nodeValue);
            break;
          case 'author':
            $author = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'createddate':
            $createdDate = parseDotNetDate($subnode->nodeValue);
            break;
          case 'due':
            $due = parseDotNetDate($subnode->nodeValue);
            break;
          case 'cust1':
            $cust1 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'cust2':
            $cust2 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'cust3':
            $cust3 = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'comments':
            $comments = $subnode->nodeValue;
            break;
          case 'status':
            $status = $subnode->nodeValue;
            break;
          case 'complete':
            $complete = $subnode->nodeValue;
            break;
          case 'icon':
            $icon = $subnode->nodeValue;
            break;
        }
      }
      $_SESSION['ftodo'][] = "$id','$category','$createdDate','$due','$title','$description','$author','$complete','$cust1','$cust2','$cust3','$comments','$status','$icon";
    }
    
    $categorynodes = $dom->getElementsByTagname('category');
    foreach($categorynodes as $categorynode) {
      $id = '';
      $name = '';      
      $owner = '';
      $type = '';
      $ispublic = '';
      $backgroundcolor = ''; 
      
      $subnodes = $categorynode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'name':
            $name = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'owner':
            $owner = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'type':
            $type = $subnode->nodeValue;
            break;
          case 'ispublic':
            $ispublic = $subnode->nodeValue;
            break;
          case 'backgroundcolor':
            $backgroundcolor = $subnode->nodeValue;
            break;
        }
      }
      if(strlen(trim($name)) > 0) {
        $_SESSION['fcats'][$type][] = $id.'__X__'.$name.'__X__'.$owner.'__X__'.$ispublic.'__X__'.$backgroundcolor;
        $lcats[] = $name;
      }
    }
    
    $commentnodes = $dom->getElementsByTagname('comment');
    foreach($commentnodes as $commentnode) {
      $id = '';
      $postid = '';      
      $author = '';
      $posted = '';
      $text = '';
      
      $subnodes = $commentnode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'postid':
            $postid = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'author':
            $author = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'posted':
            $posted = parseDotNetDate($subnode->nodeValue);
            break;
          case 'text':
            $text = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
        }
      }
      $_SESSION['fcomments'][] = "$id','$postid','$author','$posted','$text'";
    }
    $settingnodes = $dom->getElementsByTagname('setting');
    $setIZ_OPT = false;
    $setIZ_NV = false;
    foreach($settingnodes as $settingnode) {
      $settingname = $settingnode->getAttribute('name');
      switch($settingname) {
        case 'IZ_ALLOWENDDATE':
        case 'IZ_ALLOWATTENDEES':
        case 'IZ_ALLOWVENUE':
        case 'IZ_ALLOWGOOGLE':
        case 'IZ_ALLOWICON':
        case 'IZ_ALLOWCAT':
        case 'IZ_ALLOWRECURRENCE':
        case 'IZ_ALLOWFILTERS':
        case 'IZ_ALLOWGOTO':
        case 'IZ_ALLOWTODO':
        case 'IZ_ALLOWREG':
          if(!$setIZ_OPT) {
            $_SESSION['fsettings'][] = 'IZ_OPT\',\'2047';
            $setIZ_OPT = true;
          }
          break;
        case 'IZ_ALLOWCUST':
        case 'IZ_ALLOWSETTINGS':
        case 'IZ_ALLOWEVMGR':
        case 'IZ_ALLOWRSS':
        case 'IZ_ALLOWICAL':
        case 'IZ_ALLOWSEARCH':
        case 'IZ_ALLOWREPORTS':
        case 'IZ_ALLOWPRINT':
        case 'IZ_ALLOWHELP':
        case 'IZ_ALLOWVIEWDAY':
        case 'IZ_ALLOWVIEWWEEK':
        case 'IZ_ALLOWVIEWMONTH':
        case 'IZ_ALLOWVIEWEXTMONTH':
        case 'IZ_ALLOWVIEWYEAR':
          if(!$setIZ_NV) {
            $_SESSION['fsettings'][] = 'IZ_NV\',\'8191';
            $setIZ_NV = true;
          }
          break;
        case 'IZ_FIRSTDAY':
          $_SESSION['fsettings'][] = 'IZ_FIRSTDAY\',\'0';
        default:
          $_SESSION['fsettings'][] = $settingname.'\',\''.$settingnode->nodeValue;
          break;
      }
    }
//    var_dump($_SESSION['fsettings']);
    $usernodes = $dom->getElementsByTagname('user');
    foreach($usernodes as $usernode) {
      $id = '';
      $name = '';
      $usergroup = '';
      $password = '';
      $language = '';
      $daysize = '';
      $firstdayofweek = '0';
      $theme = '';
      $defaultstatus = '';
      $showall = '1';
      $dateformat = '';
      $defaultcategoryevents = '';
      $defaultcategorytasks = '';
      $pageafter = '';
      $fontsize = '';
      $collapsestatus = '';
      $color = '';
      $viewdetails = '1';
      $includecomplete = '1';
      
      $subnodes = $usernode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'name':
            $name = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'usergroup':
            $usergroup = $subnode->nodeValue;
            break;
          case 'password':
//            if(version_compare($_SESSION['backupmeta']['izver'],'3.3.0') === -1) {
              // pre 3.3.0, passwords were just md5s without salt, and since md5 hashing is one way, there's no way to rehash
              $password = saltpassword('password');
              $oldpasswords = true;
  //          } else {
    //          $password = $subnode->nodeValue;
      //      }
            break;
          case 'language':
            $language = $subnode->nodeValue;
            break;
          case 'daysize':
            $daysize = $subnode->nodeValue;
            break;  
          case 'firstdayofweek':
            $firstdayofweek = intval($subnode->nodeValue);
            break;
          case 'theme':
            $theme = $subnode->nodeValue;
            break;  
          case 'defaultstatus':
            $defaultstatus = $subnode->nodeValue;
            break;
          case 'showall':
            $showall = $subnode->nodeValue;
            break;  
          case 'defaultcategoryevents':
            $defaultcategoryevents = $subnode->nodeValue;
            break;
          case 'defaultcategorytasks':
            $defaultcategorytasks = $subnode->nodeValue;
            break;  
          case 'pageafter':
            $pageafter = $subnode->nodeValue;
            break;
          case 'fontsize':
            $fontsize = $subnode->nodeValue;
            break;
          case 'collapsestatus':
            $collapsestatus = $subnode->nodeValue;
            break;
          case 'color':
          case 'colour':
            $color = $subnode->nodeValue;
            break;
          case 'viewdetails':
            $viewdetails = $subnode->nodeValue;
            break;
          case 'includecomplete':
            $includecomplete = $subnode->nodeValue;
            break;

        }
      }
      $_SESSION['fusers'][] = "$id','$name','$usergroup','$password','$language','$daysize','$firstdayofweek','$theme','$defaultstatus','$showall','$dateformat','$defaultcategoryevents','$defaultcategorytasks','$pageafter','$fontsize','$collapsestatus','$color','$viewdetails','$includecomplete";
      $lusers[] = $name;
    }
    
    $groupnodes = $dom->getElementsByTagname('group');
    foreach($groupnodes as $groupnode) {
      $id = '';
      $name = '';
      $view = 1;
      $edit = 0;
      $delete = 0;
      $cpanel = 0;
      $customise = 0;
      $comment = 0;
      
      $subnodes = $groupnode->childNodes;
      foreach($subnodes as $subnode) {
        switch(strtolower($subnode->nodeName)) {
          case 'id':
            $id = $subnode->nodeValue;
            break;
          case 'name':
            $name = xmlUnescapeDbEscape($subnode->nodeValue);
            break;
          case 'canview':
            $view = $subnode->nodeValue;
            break;
          case 'canedit':
            $edit = $subnode->nodeValue;
            break;
          case 'candelete':
            $delete = $subnode->nodeValue;
            break;
          case 'canadministrate':
            $cpanel = $subnode->nodeValue;
            break;  
          case 'cancustomise':
            $customise = $subnode->nodeValue;
            break;
          case 'cancomment':
            $comment = $subnode->nodeValue;
            break;
        }
      }
      $_SESSION['fgroups'][] = "$id','$name','$view','$edit','$delete','$cpanel','$customise','$comment";
    }
  } else {
    echo str_replace('{0}',$filename,ADM_F-LOADITEM);
  }
}
} else {
  // Directly accessed
  header('Location: ../');
}
?>